package com.nervenets.shopping.hibernate.domain.common;

import com.nervenets.general.adapter.jsonType.LongArrayJson;
import com.nervenets.general.hibernate.DomainObject;
import com.nervenets.shopping.enumeration.Gender;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Type;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Index;
import javax.persistence.Table;
import java.util.List;

/**
 * 地址
 */
@EqualsAndHashCode(callSuper = true)
@Entity
@Table(
        indexes = {
                @Index(name = "index_of_latlng", columnList = "longitude,latitude")
        }
)
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Address extends DomainObject {
    @ApiModelProperty(value = "拥有者ID")
    private long userId;
    @ApiModelProperty(value = "联系人姓名")
    @Column(columnDefinition = "varchar(10)")
    private String name;
    @ApiModelProperty(value = "性别")
    @Column(columnDefinition = "tinyint")
    private Gender gender;
    @ApiModelProperty(value = "电话")
    @Column(columnDefinition = "varchar(20)")
    private String mobile;
    @ApiModelProperty(value = "地区IDs")
    @Type(type = LongArrayJson.NAME)
    @Column(columnDefinition = "json")
    private List<Long> areaIds;
    @ApiModelProperty(value = "详细地址")
    private String detail;
    @ApiModelProperty(value = "经度")
    private double longitude = 0;
    @ApiModelProperty(value = "纬度")
    private double latitude = 0;
    @ApiModelProperty(value = "是否默认")
    private boolean def = false;
}
